/*************************************************************************
	> File Name: P1714.cpp
	> Author: yufangze
	> Mail: 2224590123@qq.com
	> Created Time: 2025-01-03 10:35:54
 ************************************************************************/
#include <iostream>
#include <deque>
using namespace std;

#define MAX_N 500000
int sum[MAX_N + 5];

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 1, x; i <= n; i++) {
        cin >> x;
        sum[i] = sum[i - 1] + x;
    }
    deque<int> q(1, 0);
    int max_num = INT32_MIN;
    for (int i = 1; i <= n; i++) {
        while (!q.empty() && q.front() + m < i) q.pop_front();
        max_num = max(max_num, sum[i] - sum[q.front()]);
        while (!q.empty() && sum[q.back()] >= sum[i]) q.pop_back();
        q.push_back(i);
    }
    cout << max_num << endl;
    return 0;
}
